package com.example.a022.myapplication;

import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;

import android.support.design.widget.TabLayout;

import java.util.ArrayList;

public class Main2Activity extends AppCompatActivity {
    private ViewPager viewPager;
    private TabLayout TabLayout;
    private ArrayList<Fragment> listViews;
    private String[] titles = new String[]{"首页","关注","待购"};



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);
        getSupportActionBar().hide();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        init();

        listViews = new ArrayList<>();
        listViews.add(new HomeFragment());
        listViews.add(new HomeFragment());
        listViews.add(new HomeFragment());

        TitleFragmentPagerAdapter adapter = new TitleFragmentPagerAdapter(getSupportFragmentManager(),listViews,titles);
        viewPager.setOffscreenPageLimit(3);//ViewPager的缓存为3帧
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(0);//初始设置ViewPager选中第一帧

        TabLayout.setupWithViewPager(viewPager);

    }

    private void init() {
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        TabLayout = (android.support.design.widget.TabLayout) findViewById(R.id.tabLayout);
    }

}
